package com.kaishengit.action;

import java.io.UnsupportedEncodingException;
import java.text.ParseException;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.apache.struts2.interceptor.ServletRequestAware;

import com.kaishengit.pojo.Deal;
import com.kaishengit.pojo.DealContact;
import com.kaishengit.pojo.Note;
import com.kaishengit.pojo.User;
import com.kaishengit.service.DealContactService;
import com.kaishengit.service.DealService;
import com.kaishengit.service.NoteService;
import com.opensymphony.xwork2.ActionSupport;

public class NoteAction extends ActionSupport implements ServletRequestAware {
	private static final long serialVersionUID = 1L;
	
	private Note note;
	private NoteService noteService;
	private String contactid;
	private String dealid;
	private HttpServletRequest request;
	private List<Note> noteList;
	private String id;
	private DealContactService dealContactService;
	private List<DealContact> dcList;
	private String content;
	
	
	public String execute(){
		return SUCCESS;
	}
	

	/**
	 * 添加和交易相关的note
	 * @return
	 * @throws ParseException 
	 */
	public String adddealnote() throws ParseException{
		HttpSession session = request.getSession();
		User user = (User) session.getAttribute("curr_user");
		note.setUser(user);
		System.out.println(contactid);
		System.out.println(note.getCreatetime()+"****************");
		noteService.saveNote(note,dealid,contactid);
		return "success";	
	}
	
	public String delNote(){
		noteService.delNote(id);
		return "success";
	}
	public String editNote(){
		note = noteService.findNote(id);
		note.setDeal(null);
		note.setUser(null);
		return SUCCESS;
	}
	public String toeditNote() throws UnsupportedEncodingException{
		note = noteService.findNote(id);
		content = new String(content.getBytes("ISo8859-1"),"utf-8");
		System.out.println(content);
		note.setContent(content);
		noteService.update(note);
		note.setDeal(null);
		//note.setUser(null);
		return SUCCESS;
	}
	
	//set
	
	public void setNoteService(NoteService noteService) {
		this.noteService = noteService;
	}

	

	public Note getNote() {
		return note;
	}

	public void setNote(Note note) {
		this.note = note;
	}

	public String getContactid() {
		return contactid;
	}

	public void setContactid(String contactid) {
		this.contactid = contactid;
	}

	public String getDealid() {
		return dealid;
	}

	public void setDealid(String dealid) {
		this.dealid = dealid;
	}

	public void setServletRequest(HttpServletRequest request) {
		this.request = request;
		
	}

	public List<Note> getNoteList() {
		return noteList;
	}

	public void setNoteList(List<Note> noteList) {
		this.noteList = noteList;
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}


	public void setDealContactService(DealContactService dealContactService) {
		this.dealContactService = dealContactService;
	}


	public List<DealContact> getDcList() {
		return dcList;
	}


	public void setDcList(List<DealContact> dcList) {
		this.dcList = dcList;
	}


	public String getContent() {
		return content;
	}


	public void setContent(String content) {
		this.content = content;
	}
	
	
	

}
